//
//  MHAttributeTableViewModel.m
//  MiaoCircle
//
//  Created by Xuzhengrong on 2018/8/19.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHAttributeTableViewModel.h"
#import "MHAttributeModel.h"
#import "MHMomentDetailViewModel.h"

@implementation MHAttributeTableViewModel
-(void)initialize
{
    [super initialize];
    self.title = @"赞了我";
    @weakify(self);
    [[MHNotificationCenter rac_addObserverForName:MHRefreshRealthToMeNotification object:nil] subscribeNext:^(NSNotification * note) {
        /// 这里切换根控制器
        @strongify(self);
        if ([note.object isKindOfClass:[MHAttributeModel class]]) {
            MHAttributeModel *message =  note.object;
            NSMutableArray *datas =  [self.datas mutableCopy];
            [datas prependObject:message];
            self.datas = [datas copy];
        }
    }];
    self.didSelectCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        @strongify(self);
        NSIndexPath *indexPath = input;
        MHAttributeModel *message =  self.datas[indexPath.row];
        
        if(message.vedioObj)
        {
           return   [[[self.services.client getRecentInfoByNewVideoWithRecentId:message.recentId] mh_parsedResults] doNext:^(MHAwemeModel *model) {
                MHAwemeListViewModel *viewModel = [[MHAwemeListViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey:@[model],@"MHViewModelShowEnterBtn":@false,@"MHViewModelShowSingleVideo":@true}];
                [self.services pushViewModel:viewModel animated:YES];
            }];
        }else
        {
            
        MHMomentDetailViewModel *detail = [[MHMomentDetailViewModel alloc] initWithServices:self.services params:@{MHViewModelIDKey:@(message.recentId),MHViewModelIsDetail:@(true)}];
        detail.isRealateToMe = YES;
//        detail.message = message;
//        detail.messageType = message.type;
        [self.services pushViewModel:detail animated:YES];
        }
        return [RACSignal empty];
    }];
    
}

-(RACSignal *)customSignalWithPage:(NSInteger)page
{
    return  [self.services.client getUserRecentLikePagedList:page pageSize:self.perPage];
}
@end
